﻿using Cms.Application.Admin.Views;
using Cms.Data;
using Cms.Domain;
using Cms.Domain.RepositoryInterfaces;

namespace Cms.Application.Admin.Presenters
{
    public class CommentsPresenter : BasePresenter
    {
        private readonly ICommentsView _view;
        private readonly Administrator _administrator;
        
        public CommentsPresenter(ICommentsView view)
            : this(view, new RepositoryFactory())
        {
        }

        public CommentsPresenter(ICommentsView view, IRepositoryFactory repositoryFactory)
            : base(view, repositoryFactory)
        {
            _view = view;
            _administrator = AdministratorRepository.GetAdministrator(_view.AdministratorID);
            if (!_administrator.HasPermission.Comments)
                _view.RedirectToPermissionDeniedPage();
        }
        
        public void Initialize()
        {
            SetComments();
        }

        public void SetComments()
        {
            _view.SetComments(PageRepository.GetComments());
        }

        public void DeleteComment(int id)
        {
            Comment comment = PageRepository.GetComment(id);
        }
    }
}